class Solution {
    public int searchInsert(int[] nums, int target) {
        int pos = 0;
        for(int i = 0;i < nums.length - 1;i ++){
            if(nums[i] < target && nums[i + 1] > target){
                pos = i + 1;
            }
            if(nums[i] == target){
                pos = i;
            }
        }
        if(nums[nums.length - 1] == target){
            pos = nums.length - 1;
        }
        if(nums[nums.length - 1] < target){
            pos = nums.length;
        }
        return pos;
    }
}